package com.oracle.lingshangejia.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.oracle.lingshangejia.R;
import com.oracle.lingshangejia.bean.SeekMedicineBean;

import java.util.List;

public class NoSovledAdapter extends RecyclerView.Adapter<NoSovledAdapter.ViewHolder> {

    private Context context;
    private OnItemClickListener listener;
    private List<SeekMedicineBean.DataBean> data;
    public interface OnItemClickListener {
        void onItemClick(View view, int whyId);
    }
    public void setOnItemClickListener(OnItemClickListener listener) {
        this.listener = listener;
    }
    public NoSovledAdapter(Context context, List<SeekMedicineBean.DataBean> data){
        this.data=data;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

        View view = LayoutInflater.from(context).inflate(R.layout.item_seekmedicine,null);

        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        viewHolder.tv_seek_title.setText(data.get(i).getWtbt());
        viewHolder.tv_seek_content.setText(data.get(i).getWdnr());
        viewHolder.tv_seek_time.setText("上报时间："+data.get(i).getCreateDate());
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onItemClick(v,i);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return data!=null?data.size():0;
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        TextView tv_seek_title;
        TextView tv_seek_content;
        TextView tv_seek_time;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_seek_title=itemView.findViewById(R.id.tv_seek_title);
            tv_seek_content=itemView.findViewById(R.id.tv_seek_content);
            tv_seek_time=itemView.findViewById(R.id.tv_seek_time);
        }
    }
}
